//
//  UIInsetLabel.swift
//  TTCOM-iOS
//
//  Created by Toj on 6/16/23.
//

import UIKit

open class UIInsetLabel: UILabel {
    
    public var lbl_contentInsets = UIEdgeInsets(top: 2, left: 2, bottom: 2, right: 2) { didSet {
        invalidateIntrinsicContentSize()
    } }
    
    open override func drawText(in rect: CGRect) {
        let inset = lbl_isEmpty ? .zero : lbl_contentInsets
        super.drawText(in: rect.inset(by: inset))
    }
    
    open override var intrinsicContentSize: CGSize {
        var size = super.intrinsicContentSize
        let inset = lbl_isEmpty ? .zero : lbl_contentInsets
        size.width += inset.st_horizontal
        size.height += inset.st_vertical
        return size
    }
}
